import requests


headers = {
    "Accept": "application/json",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Type": "application/json",
    "Origin": "https://fuwu.nhsa.gov.cn",
    "Pragma": "no-cache",
    "Referer": "https://fuwu.nhsa.gov.cn/nationalHallSt/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0",
    "X-Tingyun": "c=B|4Nl_NnGbjwY;x=081b12bf3be24f0b",
    "channel": "web",
    "contentType": "application/x-www-form-urlencoded",
    "sec-ch-ua": "\"Chromium\";v=\"142\", \"Microsoft Edge\";v=\"142\", \"Not_A Brand\";v=\"99\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "x-tif-nonce": "Y42qQVzR",
    "x-tif-paasid": "undefined",
    "x-tif-signature": "942b8682bb551cdcd78570484d0f211a7ec7a53726946e27aaae71497bfe3051",
    "x-tif-timestamp": "1762939319"
}
cookies = {
    "yb_header_active": "-1",
    "acw_tc": "276aede817629380750038525e0800661b71c9c56d7c599400f80d936442f6",
    "amap_local": "430300"
}
url = "https://fuwu.nhsa.gov.cn/ebus/fuwu/api/nthl/api/CommQuery/queryFixedHospital"


import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
import json
with open("04-1.js", "r", encoding="utf-8") as f:
    js_code = f.read()
cpl = execjs.compile(js_code)
request_param = cpl.call('generateRequestParams',3 )
data = json.loads(request_param['data'])
response = requests.post(url, headers=headers, cookies=cookies, json=data)
print(response.text)
encrypted_res_json = json.loads(response.text)
decrypted_res = cpl.call('getDecryptResponse', encrypted_res_json)
print(decrypted_res['list'])
